using System.Collections.Generic;

using Sce.Pss.Core.Graphics;

namespace Storyteller.Framework.Graphics
{
	public class VertexBufferPool
	{
		public VertexBufferPool(int initialBufferCount, int triangleCount, params VertexFormat[] formats)
		{
			this.triangleCount = triangleCount;
			
			for(int i=0; i<initialBufferCount; i++)
			{
				cleanBuffers.Enqueue(new VertexBuffer(triangleCount, formats));
			}
		}
		
		public void Reset()
		{
			while(dirtyBuffers.Count > 0)
			{
				cleanBuffers.Enqueue(dirtyBuffers.Dequeue());
			}
		}
		
		public VertexBuffer GetBuffer()			
		{
			VertexBuffer vertexBuffer;
			
			if(cleanBuffers.Count > 0)
				vertexBuffer = cleanBuffers.Dequeue();
			else
				vertexBuffer = new VertexBuffer(triangleCount, VertexFormat.Float3, VertexFormat.Float2, VertexFormat.Float4);
			
			dirtyBuffers.Enqueue(vertexBuffer);
			return vertexBuffer;
		}
		
		int triangleCount;
		
		Queue<VertexBuffer> cleanBuffers = new Queue<VertexBuffer>();
		Queue<VertexBuffer> dirtyBuffers = new Queue<VertexBuffer>();
	}
}

